package com.ly.auth.service.impl;

import com.ly.auth.entity.AuthUser;
import com.ly.auth.mapper.auth.UserMapper;
import com.ly.auth.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Objects;


@Service("springDataUserDetailsService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    //根据 账号查询用户信息
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        AuthUser sysUser = userMapper.getUserByUserNameOrPhone(username);
        if(Objects.isNull(sysUser)) {
            throw new UsernameNotFoundException("用户名不存在！");
        }
        return sysUser;
    }
}
